package com.dingwei.superiordiary.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.dingwei.superiordiary.R;
import com.dingwei.superiordiary.bean.SetStateBean;
import com.dingwei.superiordiary.mvp.presenter.PrivacySetPresenter;
import com.dingwei.superiordiary.mvp.view.Contract;
import com.lihao.baselibrary.base.BaseActivity;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author 南柯一梦丶
 * Created time 2018/10/22.
 * Personal signature 余生还长 何必慌张
 * Page description :
 * .::::.
 * .::::::::.
 * :::::::::::
 * ..:::::::::::'
 * '::::::::::::'
 * .::::::::::
 * '::::::::::::::..
 * ..::::::::::::.
 * ``::::::::::::::::
 * ::::``:::::::::'        .:::.
 * ::::'   ':::::'       .::::::::.
 * .::::'      ::::     .:::::::'::::.
 * .:::'       :::::  .:::::::::' ':::::.
 * .::'        :::::.:::::::::'      ':::::.
 * .::'         ::::::::::::::'         ``::::.
 * ...:::           ::::::::::::'              ``::.
 * ```` ':.          ':::::::::'                  ::::..
 * '.:::::'                    ':'````..
 */
public class PrivacyActivity extends BaseActivity implements Contract.PrivacyView {

    PrivacySetPresenter privacySetPresenter = new PrivacySetPresenter(this);
    @Bind(R.id.img_back)
    ImageView imgBack;
    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.tv_right)
    TextView tvRight;
    @Bind(R.id.img_search)
    ImageView imgSearch;
    @Bind(R.id.img_maillist)
    ImageView imgMaillist;

    @Override
    protected int getContentViewId() {
        return R.layout.activity_privacy_set;
    }

    @Override
    protected void initData() {
        privacySetPresenter.initData();
    }

    @Override
    protected void initView() {
        tvTitle.setText("隐私设置");
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }


    SetStateBean bean;

    @Override
    public void setData(SetStateBean bean) {
        this.bean = bean;
        if (bean.data.is_rec_maillist.equals("1")) {
            imgMaillist.setImageResource(R.mipmap.ic_set_open);
        } else {
            imgMaillist.setImageResource(R.mipmap.ic_set_close);
        }
        if (bean.data.is_sreach_mobile.equals("1")) {
            imgSearch.setImageResource(R.mipmap.ic_set_open);
        } else {
            imgSearch.setImageResource(R.mipmap.ic_set_close);
        }
    }

    @Override
    public void privacySettingSuccess() {
        privacySetPresenter.initData();
    }


    @OnClick({R.id.img_back, R.id.img_search, R.id.img_maillist, R.id.review_permissions_layout, R.id.black_layout})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.img_search:
                if (bean.data.is_sreach_mobile.equals("1")) {
                    bean.data.is_sreach_mobile = "0";
                } else {
                    bean.data.is_sreach_mobile = "1";
                }
                privacySetPresenter.privacySetting(bean.data.is_sreach_mobile, bean.data.is_rec_maillist);
                break;
            case R.id.img_maillist:
                if (bean.data.is_rec_maillist.equals("1")) {
                    bean.data.is_rec_maillist = "0";
                } else {
                    bean.data.is_rec_maillist = "1";
                }
                privacySetPresenter.privacySetting(bean.data.is_sreach_mobile, bean.data.is_rec_maillist);
                break;
            case R.id.review_permissions_layout:
                intent = new Intent(BaseActivity.context, ReviewPermissionsActivity.class);
                startActivity(intent);
                break;
            case R.id.black_layout:
                intent = new Intent(BaseActivity.context, BlackListActivity.class);
                startActivity(intent);

                break;
        }
    }
}
